SlideShare a Scribd company logo
Class No.27  Data Structures http://ecomputernotes.com
Priority Queue Using Heap #include “Event.cpp” #include “Heap.cpp” #define PQMAX 30 class PriorityQueue  { public: PriorityQueue() { heap = new Heap<Event>( PQMAX ); }; ~PriorityQueue() { delete heap; }; http://ecomputernotes.com
Priority Queue Using Heap Event* remove() { if( !heap->isEmpty() ) { Event* e;  heap->deleteMin( e ); return e; } return (Event*)NULL; cout << &quot;remove - queue is empty.&quot; << endl; }; http://ecomputernotes.com
Priority Queue Using Heap int insert(Event* e)  { if( !heap->isFull() ) { heap->insert( e ); return 1; } cout << &quot;insert queue is full.&quot; << endl; return 0; }; int full(void){ return heap->isFull(); }; int length() { return heap->getSize(); }; };  http://ecomputernotes.com
The Selection Problem Given a list of  N  elements (numbers, names etc.), which can be totally ordered, and an integer  k , find the  k th smallest (or largest) element. One way is to put these  N  elements in an array an sort it. The  k th  smallest of these is at the  k th  position. http://ecomputernotes.com
The Selection Problem A faster way is to put the  N  elements into an array and apply the  buildHeap  algorithm on this array. Finally, we perform  k deleteMin  operations. The last element extracted from the heap is our answer. The interesting case is  k  =  N /2, since this is known as the  median . http://ecomputernotes.com
HeapSort If  k  =  N , and we record the  deleteMin  elements as they come off the heap, we will have essentially sorted the  N  elements. Later in the course, we will refine this idea to obtain a fast sorting algorithm called  heapsort . http://ecomputernotes.com
Disjoint Set ADT Suppose we have a database of people. We want to figure out who is related to whom. Initially, we only have a list of people, and information about relations is gained by updates of the form “Haaris is related to Saad”. http://ecomputernotes.com
Disjoint Set ADT Key property: If Haaris is related to Saad and Saad is related to Ahmad, then Haaris is related to Ahmad. Once we have relationships information, we would like to answer queries like “Is Haaris related to Ahmad?” http://ecomputernotes.com
Disjoint Set ADT Blob Coloring A well-known low-level computer vision problem for black and white images is the following: Gather together all the picture elements (pixels) that belong to the same &quot;blobs&quot;, and give each pixel in each different blob an identical label.  http://ecomputernotes.com
Disjoint Set ADT Blob Coloring Thus in the following image, there are five blobs.  We want to  partition  the pixels into  disjoint sets , one set per blob. http://ecomputernotes.com
Disjoint Set ADT The image segmentation problem. http://ecomputernotes.com
Equivalence Relations A binary relation  over a set S is called an  equivalence relation  if it has following properties Reflexivity: for all element xS, x  x Symmetry: for all elements x and y, x  y if and only if y  x Transitivity: for all elements x, y and z, if x  y and y  z then x  z The relation “is related to” is an equivalence relation over the set of people http://ecomputernotes.com
Equivalence Relations The  relationship is  not  an equivalence relation.  It is reflexive, since x  x,  and transitive, since x  y and y  z  implies x  z,  it is  not symmetric  since x  y does not imply y  x. http://ecomputernotes.com

More Related Content

PDF
Echo Function
PPTX
130717666736980000
PPT
Sets and disjoint sets union123
PPT
computer notes - Data Structures - 35
PPSX
Data structure stack&queue basics
PPT
computer notes - Data Structures - 8
PPT
computer notes - Data Structures - 26
PPT
computer notes - Data Structures - 29
Echo Function
130717666736980000
Sets and disjoint sets union123
computer notes - Data Structures - 35
Data structure stack&queue basics
computer notes - Data Structures - 8
computer notes - Data Structures - 26
computer notes - Data Structures - 29

Viewers also liked (20)

PPT
computer notes - Data Structures - 1
PPT
computer notes - Data Structures - 18
PPT
computer notes - Data Structures - 10
PPT
computer notes - Data Structures - 3
PPT
computer notes - Data Structures - 15
PPT
computer notes - Data Structures - 13
PPT
computer notes - Data Structures - 14
PPT
computer notes - Data Structures - 4
PPT
computer notes - Data Structures - 12
PPT
computer notes - Data Structures - 20
PPT
computer notes - Data Structures - 9
PPT
computer notes - Data Structures - 38
PPT
computer notes - Data Structures - 11
PPT
computer notes - Data Structures - 6
PPT
computer notes - Data Structures - 23
PPT
computer notes - Data Structures - 28
PPT
computer notes - Data Structures - 2
PPT
computer notes - Data Structures - 25
PDF
computer notes - Deleting a node
PPT
computer notes - Data Structures - 33
computer notes - Data Structures - 1
computer notes - Data Structures - 18
computer notes - Data Structures - 10
computer notes - Data Structures - 3
computer notes - Data Structures - 15
computer notes - Data Structures - 13
computer notes - Data Structures - 14
computer notes - Data Structures - 4
computer notes - Data Structures - 12
computer notes - Data Structures - 20
computer notes - Data Structures - 9
computer notes - Data Structures - 38
computer notes - Data Structures - 11
computer notes - Data Structures - 6
computer notes - Data Structures - 23
computer notes - Data Structures - 28
computer notes - Data Structures - 2
computer notes - Data Structures - 25
computer notes - Deleting a node
computer notes - Data Structures - 33
Ad

Similar to computer notes - Data Structures - 27 (20)

PPT
Computer notes - Josephus Problem
PPT
computer notes - Data Structures - 5
ODP
Pick up the low-hanging concurrency fruit
DOCX
Optimization Of Fuzzy Bexa Using Nm
PPT
introduction to stack data structures chapter 1
PPT
MODULE 01-INTRODUCTION TO STACK-PRESENTATION
PDF
Read carefully. Im not sure if the point class is correct but postin.pdf
PPT
Computer notes - data structures
PPT
Data Structure In C#
PPT
introduction stacks in data structures and algorithms
PPT
An Introduction to Stack Data Structures
PDF
E6
PPT
C++: inheritance, composition, polymorphism
PPT
01-intro_stacks.ppt
PPT
Chap 4 List of Data Structure.ppt
PPT
Lecture 5 Inheritance
PDF
Lambda? You Keep Using that Letter
PPTX
DA_02_algorithms.pptx
PPTX
Getting started with ES6
Computer notes - Josephus Problem
computer notes - Data Structures - 5
Pick up the low-hanging concurrency fruit
Optimization Of Fuzzy Bexa Using Nm
introduction to stack data structures chapter 1
MODULE 01-INTRODUCTION TO STACK-PRESENTATION
Read carefully. Im not sure if the point class is correct but postin.pdf
Computer notes - data structures
Data Structure In C#
introduction stacks in data structures and algorithms
An Introduction to Stack Data Structures
E6
C++: inheritance, composition, polymorphism
01-intro_stacks.ppt
Chap 4 List of Data Structure.ppt
Lecture 5 Inheritance
Lambda? You Keep Using that Letter
DA_02_algorithms.pptx
Getting started with ES6
Ad

More from ecomputernotes (18)

PPT
computer notes - Data Structures - 30
PPT
computer notes - Data Structures - 39
DOC
Computer notes - Including Constraints
DOC
Computer notes - Date time Functions
DOC
Computer notes - Subqueries
DOC
Computer notes - Other Database Objects
PPT
computer notes - Data Structures - 19
PPT
computer notes - Data Structures - 31
DOC
Computer notes - Advanced Subqueries
DOC
Computer notes - Aggregating Data Using Group Functions
PPT
computer notes - Data Structures - 16
PPT
computer notes - Data Structures - 22
PPT
computer notes - Data Structures - 36
DOC
Computer notes - Enhancements to the GROUP BY Clause
DOC
Computer notes - Manipulating Data
DOC
Computer notes - Writing Basic SQL SELECT Statements
DOC
Computer notes - Controlling User Access
DOC
Computer notes - Using SET Operator
computer notes - Data Structures - 30
computer notes - Data Structures - 39
Computer notes - Including Constraints
Computer notes - Date time Functions
Computer notes - Subqueries
Computer notes - Other Database Objects
computer notes - Data Structures - 19
computer notes - Data Structures - 31
Computer notes - Advanced Subqueries
Computer notes - Aggregating Data Using Group Functions
computer notes - Data Structures - 16
computer notes - Data Structures - 22
computer notes - Data Structures - 36
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Manipulating Data
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Controlling User Access
Computer notes - Using SET Operator

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
Spectral efficient network and resource selection model in 5G networks

computer notes - Data Structures - 27

  • 1. Class No.27 Data Structures http://ecomputernotes.com
  • 2. Priority Queue Using Heap #include “Event.cpp” #include “Heap.cpp” #define PQMAX 30 class PriorityQueue { public: PriorityQueue() { heap = new Heap<Event>( PQMAX ); }; ~PriorityQueue() { delete heap; }; http://ecomputernotes.com
  • 3. Priority Queue Using Heap Event* remove() { if( !heap->isEmpty() ) { Event* e; heap->deleteMin( e ); return e; } return (Event*)NULL; cout << &quot;remove - queue is empty.&quot; << endl; }; http://ecomputernotes.com
  • 4. Priority Queue Using Heap int insert(Event* e) { if( !heap->isFull() ) { heap->insert( e ); return 1; } cout << &quot;insert queue is full.&quot; << endl; return 0; }; int full(void){ return heap->isFull(); }; int length() { return heap->getSize(); }; }; http://ecomputernotes.com
  • 5. The Selection Problem Given a list of N elements (numbers, names etc.), which can be totally ordered, and an integer k , find the k th smallest (or largest) element. One way is to put these N elements in an array an sort it. The k th smallest of these is at the k th position. http://ecomputernotes.com
  • 6. The Selection Problem A faster way is to put the N elements into an array and apply the buildHeap algorithm on this array. Finally, we perform k deleteMin operations. The last element extracted from the heap is our answer. The interesting case is k =  N /2, since this is known as the median . http://ecomputernotes.com
  • 7. HeapSort If k = N , and we record the deleteMin elements as they come off the heap, we will have essentially sorted the N elements. Later in the course, we will refine this idea to obtain a fast sorting algorithm called heapsort . http://ecomputernotes.com
  • 8. Disjoint Set ADT Suppose we have a database of people. We want to figure out who is related to whom. Initially, we only have a list of people, and information about relations is gained by updates of the form “Haaris is related to Saad”. http://ecomputernotes.com
  • 9. Disjoint Set ADT Key property: If Haaris is related to Saad and Saad is related to Ahmad, then Haaris is related to Ahmad. Once we have relationships information, we would like to answer queries like “Is Haaris related to Ahmad?” http://ecomputernotes.com
  • 10. Disjoint Set ADT Blob Coloring A well-known low-level computer vision problem for black and white images is the following: Gather together all the picture elements (pixels) that belong to the same &quot;blobs&quot;, and give each pixel in each different blob an identical label. http://ecomputernotes.com
  • 11. Disjoint Set ADT Blob Coloring Thus in the following image, there are five blobs. We want to partition the pixels into disjoint sets , one set per blob. http://ecomputernotes.com
  • 12. Disjoint Set ADT The image segmentation problem. http://ecomputernotes.com
  • 13. Equivalence Relations A binary relation  over a set S is called an equivalence relation if it has following properties Reflexivity: for all element xS, x  x Symmetry: for all elements x and y, x  y if and only if y  x Transitivity: for all elements x, y and z, if x  y and y  z then x  z The relation “is related to” is an equivalence relation over the set of people http://ecomputernotes.com
  • 14. Equivalence Relations The  relationship is not an equivalence relation. It is reflexive, since x  x, and transitive, since x  y and y  z implies x  z, it is not symmetric since x  y does not imply y  x. http://ecomputernotes.com

Editor's Notes

  • #3: Start of lecture 33
  • #7: buildHeap is O ( N ) operation. Each deleteMin is O (log 2 N ). The total running time is thus O ( N + k log 2 N ). If k is small, or O ( N / log 2 N ), then the time required is O ( N ).
  • #14: End of lecture 33, Start of lecture 34